<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@page import="com.crm.entity.Opportunity,com.crm.entity.Supplier,java.util.*" %>
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/temp.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<!-- InstanceEndEditable -->
<link href="<%=application.getContextPath()%>/css/css-crm.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=application.getContextPath()%>/js/jquery-1.6.min.js"></script>	
<script type="text/javascript" src="<%=application.getContextPath()%>/js/jquery-ui-1.8.17.custom.min.js"></script>	
<link rel="stylesheet" href="<%=application.getContextPath()%>/css/jquery-ui-1.8.17.custom.css"/>
<script language="JavaScript" src="<%=application.getContextPath()%>/js/gen_validatorv4.js" type="text/javascript" ></script>
<script type="text/javascript" src="<%=application.getContextPath()%>/js/jquery.validate.js"></script>	
<script type="text/javascript" src="<%=application.getContextPath()%>/js/jquery.validate.min.js"></script>

<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->

<script>

	$(function() {
		$( "#datepicker" ).datepicker({ dateFormat: "dd-mm-yy" },"option", "autoSize", true);
	});
</script>
</head>


<body>
<%List<Supplier> suplist =(List<Supplier>)request.getAttribute("supplier");%>
<%List<Opportunity> opprtlist =(List<Opportunity>)request.getAttribute("opprtunity");%>
<div id="main">
  <%@include file="common/header.jsp" %>
  <%@include file="common/submenu.jsp" %>
  
  <div id="content">
  <div id="resultMsg"  align="center" class="result_msg">
    <% 
   String msg= request.getParameter("msg");
    	if(msg!=null){
    		System.out.println(msg);
    		out.println(msg);
    	}
    	
    %>
    </div>
  <div id="Msg"  align="center" class="result_msg">
    <% 
   
    	if(request.getAttribute("msg")!=null){
    		String mes= request.getAttribute("msg").toString();
    		System.out.println(mes);
    		out.println(mes);
    	}
    	
    %>
    </div>
      <div id="enqclient" style="display: none;" align="center" class="result_msg">

    </div>
  <form  id="sinform" action="<%=application.getContextPath() %>/suppInvoice/saveInvoice.do"  enctype="multipart/form-data" method="post">
    <div id="work-area2">
      <div class="heading2">Supplier Invoice</div>
	  
      <div class="boxIFS">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td align="right">&nbsp;</td>
              <td align="right" valign="middle">&nbsp;</td>
              <td align="right" valign="middle">&nbsp;</td>
              <td align="right" valign="middle">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
            </tr>
            <tr>
              <td width="18%" align="right">Reference Number:</td>
              <td width="24%" align="right" valign="middle">
                <select name="reflist" class="form" id="reflistid">
                 <option  value="">Please Select</option>
         <% 
              if(opprtlist!=null){
            	  System.out.println("the size of the pr list is "+opprtlist.size());
	      	for(int i=0;i<opprtlist.size();i++){
	      	%>
           <option  value="<%=opprtlist.get(i).getRefNum()%>"><%=opprtlist.get(i).getRefNum()%></option>
                   	<%	}
	              	}%>
                </select>
              </td>
              <td width="17%" align="right" valign="middle">Supplier:</td>
              <td width="23%" align="right" valign="middle">
              <select name="supplier" class="form" id="supplierid">
               <option value="">Please Select</option>
              </select></td>
              <td width="0%" align="left" valign="middle">&nbsp;</td>
              <td width="15%" align="left" valign="middle">
              <!--<input type="button" class="button" value="Get Invoice" id="getin"/>
              --></td>
              <td width="3%" align="left" valign="middle">&nbsp;</td>
            </tr>
                  
                  <tr>
              <td height="5" align="right"></td>
              <td height="5" align="right" valign="top"></td>
              <td height="5" align="left" valign="middle"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
            </tr>
                  <tr>
              <td height="5" align="right"></td>
              <td height="5" align="right" valign="top"></td>
              <td height="5" align="left" valign="middle"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
            </tr>
                  <tr>
              <td height="20" align="right"></td>
              <td height="20" align="right" valign="top"></td>
              <td height="20" align="left" valign="middle"></td>
              <td height="20" align="left" valign="top"></td>
              <td height="20" align="left" valign="top"></td>
              <td height="20" align="left" valign="top"></td>
              <td height="20" align="left" valign="top"></td>
            </tr>
            <tr>
              <td width="18%" align="right">Supplier Order Date:</td>
              <td width="24%" align="right" valign="middle"><input name="soDate" type="text" class="form" id="datepicker" />  
              
              </td>
          <td width="17%" align="right" valign="middle">Supply Order Number:</td>
              <td width="23%" align="right" valign="middle"><input name="soNo" type="text" class="form" id="soNoId" />
              </td>
              <td width="15%" align="left" valign="middle">  </td>
              <td width="15%" align="left" valign="middle">
            </td>
              <td width="3%" align="left" valign="middle">&nbsp;</td>
            </tr>
                  <tr>
              <td height="30" align="right"></td>
              <td height="30" align="right" valign="top"></td>
              <td height="30" align="left" valign="middle"></td>
              <td height="30" align="left" valign="top"></td>
              <td height="30" align="left" valign="top"></td>
              <td height="30" align="left" valign="top"></td>
              <td height="30" align="left" valign="top"></td>
            </tr>
            <tr>
            
             <td width="18%" align="right">Supplier Invoice Copy:</td>
              <td width="24%" align="right" valign="middle">  
              <input type="file" class="upload"  name="suppliercopy" id="suppliercopy"/>
              </td>
              <td width="17%" align="right" valign="middle"></td>
              <td width="23%" align="right" valign="middle"><input type="submit" class="button" value="SAVE" id="save"/>
              </td>
              <td width="15%" align="left" valign="middle">  </td>
              <td width="15%" align="left" valign="middle">
            </td>
              <td width="3%" align="left" valign="middle">&nbsp;</td>
            </tr>
            <tr>
              <td height="40" align="right"></td>
              <td height="40" align="right" valign="top"></td>
              <td height="40" align="left" valign="middle"></td>
              <td height="40" align="left" valign="top"></td>
              <td height="40" align="left" valign="top"></td>
              <td height="40" align="left" valign="top"></td>
              <td height="40" align="left" valign="top"></td>
            </tr>
             
            
          </table>
      </div>  
      
       <div id="ajaxLoader" style="display:none" align="center"><img src="<%=application.getContextPath()%>/images/ajax_loader.gif"/></div>
      <table style="height:300px; width:910px;" ><tr><td><div id="resDiv" class="boxtable" style="display:none" ></div></td></tr></table> 

	
	  
    </div>
    </form>
    <!-- InstanceEndEditable -->
    </div><div id="footer"></div>  
</div>
</body>
<!-- InstanceEnd --></html>
<script type="text/javascript">
$("#reflistid").change(function(){
	var refNo=$("#reflistid").val();
	 if(refNo==null || refNo==""){
		 jAlert("Please Select Reference Number");
		 return false;
	 }
	
	 else{
			$("#ajaxLoader").show();
	$.ajax({
		url:"<%=application.getContextPath()%>/suppInvoice/getSupplier.do",
		data:"refno="+refNo,
		method:"post",
		success:function(res){
			var e2=document.getElementById('supplierid');
			$('#supplierid')
		    .find('option')
		    .remove()
		    .end()
		   	;
			var tempres=res.split("@");
			var temp=tempres[0].split(",");
			if(temp != null || temp!=" "){
				var o=document.createElement('option');
				o.value="";
				o.text="Please Select";
				e2.options.add(o);
				for(var i=1;i<temp.length;i++){
					var o=document.createElement('option');
					o.value=temp[i];
					o.text=temp[i];
					e2.options.add(o);
				}
			}
			var clientres=tempres[1].split(",");
			 $("#enqclient").html("Client Name Is:<span class='cliendet'>"+clientres[0] +
						"</span>   &nbsp;&nbsp;&nbsp;&nbsp;  Client Division Is:<span class='cliendet'>"+clientres[1]+
						 "</span>    &nbsp;&nbsp;&nbsp;&nbsp;    Client User Is:<span class='cliendet'>"+clientres[2]+"</span>");
						 $("#enqclient").show();
		}
	}).done(function(html){
		$("#ajaxLoader").hide();
		/* alert("Ajax Loading Completed"); */
	}).fail(function(html){
		$("#ajaxLoader").hide();
		alert("Failed To Load the Data");
	});
	}
});
$("#getin").click(function(){
	var refNo=$("#reflistid").val();
	var supplier=$("#supplierid").val();
	 if(refNo==null || refNo==""){
		 jAlert("Please Select Refrence");
		 return false;
	 }
	 if(supplier==null || supplier==""){
		 jAlert("Please Select Supplier");
		 return false;
	 }
	if(refNo!=null && refNo!="" && refNo!="Please Select" && supplier!=null && supplier!="" && supplier!="Please Select" ){
		$("#ajaxLoader").show();
		$.ajax({
		url:"<%=application.getContextPath()%>/suppInvoice/getInvoice.do",
		data:"refno="+refNo+"&supplier="+supplier,
		method:"post",
		success:function(res){
			$("#resDiv").show();
			$("#resDiv").html(res);
		}
	}).done(function(html){
		$("#ajaxLoader").hide();
		/* alert("Ajax Loading Completed"); */
	}).fail(function(html){
		$("#ajaxLoader").hide();
		alert("Failed To Load the Data");
	});
	}
});
$("#supplierid").change(function(){
	var refNo=$("#reflistid").val();
	var supplier=$("#supplierid").val();
	 if(refNo==null || refNo==""){
		 jAlert("Please Select Refrence");
		 return false;
	 }
	 if(supplier==null || supplier==""){
		 jAlert("Please Select Supplier");
		 return false;
	 }
	if(refNo!=null && refNo!="" && refNo!="Please Select" && supplier!=null && supplier!="" && supplier!="Please Select" ){
		$("#ajaxLoader").show();
		$.ajax({
		url:"<%=application.getContextPath()%>/suppInvoice/getSupplyOrderNo.do",
		data:"refno="+refNo+"&supplier="+supplier,
		method:"post",
		success:function(res){
			var temp=res.split(",");
			//alert(res);
			//alert(temp);
			$("#soNoId").val(temp[0]);
			var tm=temp[1].split("-");
			$("#datepicker").val(tm[2]+"-"+tm[1]+"-"+tm[0]);
		}
	}).done(function(html){
		$("#ajaxLoader").hide();
		/* alert("Ajax Loading Completed"); */
	}).fail(function(html){
		$("#ajaxLoader").hide();
		alert("Failed To Load the Data");
	});
	}
});
</script>
<script type="text/javascript">
    $(document).ready(function(){
       $("#sinform").validate({
    	   rules:{
    		   reflist: "required",
    		   supplier: "required",
    		   quotNo: "required",
    		   soNo: {
    				required: true  
    				
    		   },
       soDate:{
    	   required: true
    	   
       },
    		   invoiceNum: "required"
    		   
    	   },
       messages:{
    	   reflist: "Refrence No is required",
    	   supplier: "Supplier is required",
    	   quotNo: "Quotation No is required",
    	   soNo: "Supplier no is required..",
    	   soDate:{
    		   required: "Supplier Order No is required.."
    	   },
    	   invoiceNum:{
        	   required: "Invoice Num requred"
           }         
       }
       });
       });
    </script> 
